package com.aglhz.nature.adapter;

import java.util.List;



import com.aglhz.nature.R;
import com.aglhz.nature.modle.item.ShopListData;
import com.aglhz.nature.view.SecondHomeWebActivity;
import com.squareup.picasso.Picasso;

import android.content.Context;
import android.content.Intent;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class ShopList2Adapter extends BaseAdapter{
	public List<ShopListData>mData;
    public Context context;
          
	public ShopList2Adapter(List<ShopListData> mData, Context context) {
		super();
		this.mData = mData;
		this.context = context;
	}
	
	
	
	
	
	
	@Override
	public int getCount() {
		return mData.size();
	}
	@Override
	public Object getItem(int position) {
		return mData.get(position);
	}
	@Override
	public long getItemId(int position) {
		return position;
	}
	@Override
	public View getView(final int position, View convertView, ViewGroup arg2) {
		 ViewHolder viewHolder; 
			if(null==convertView){			
				  convertView = LayoutInflater.from(context).inflate(R.layout.item_secclass_listview, null); 
				  viewHolder = new ViewHolder();
				  viewHolder.goodsName=(TextView)  convertView.findViewById(R.id.goodsName);
				  viewHolder.relativelayout=(RelativeLayout) convertView.findViewById(R.id.relativelayout);
					 viewHolder.second_cla_tvMoney=(TextView) convertView.findViewById(R.id.second_cla_tvMoney);				
					 viewHolder.second_cla_iv=(ImageView)  convertView.findViewById(R.id.second_cla_iv);
				
				  convertView.setTag(viewHolder); 
			}else{
				viewHolder = (ViewHolder) convertView.getTag(); 
			}
			//设置图片
//			LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);  
//			lp.setMargins((int)(getScreenWidth()*0.025), (int)(getScreenWidth()*0.025), (int)(getScreenWidth()*0.025), (int)(getScreenWidth()*0.025));		
//			viewHolder.second_cla_iv.setLayoutParams(lp); 
			//设置图片
			
				  String imgUrl = mData.get(position).getGoodsImgCover();
				//picasso加载网络图片
				   Picasso.with(context)  
				   .load(imgUrl)  	
				    .resize(getScreenWidth(), getScreenWidth()*2/5)
				   .into(viewHolder.second_cla_iv);
	   
			//设置文字
					
					viewHolder.goodsName.setText(mData.get(position).getName());
					
					viewHolder.second_cla_tvMoney.setText("￥："+mData.get(position).getPrice());
					convertView.setOnClickListener(new OnClickListener() {
						
						@Override
						public void onClick(View v) {
							Intent intent= new Intent(context,SecondHomeWebActivity.class);
							intent.putExtra("SecClassLink", mData.get(position).getLink());
							context.startActivity(intent);
							
							
						}
					});

			return convertView;
		}
		class ViewHolder 
		{  
			public TextView goodsName;
			  public RelativeLayout relativelayout;
			public TextView second_cla_tvMoney;
			public ImageView second_cla_iv;
		} 
		
		/**
		 * 获取屏幕宽度
		 * 
		 * @return
		 */
		protected int getScreenWidth() {
			WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
			Display display = wm.getDefaultDisplay();
			return display.getWidth();
		}
	} 

